const formatTime = date => {
	const year = date.getFullYear()
	const month = date.getMonth() + 1
	const day = date.getDate()
	const hour = date.getHours()
	const minute = date.getMinutes()
	const second = date.getSeconds()

	return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
	n = n.toString()
	return n[1] ? n : '0' + n
}

// 对像克隆
const clone = obj => {
    let temp = new Object;
    if(obj instanceof Array){
        temp = obj.concat();
    }else if(obj instanceof Function){
        //函数是共享的是无所谓的，js也没有什么办法可以在定义后再修改函数内容
        temp = obj;
    }else{
        temp = new Object();
        for(let item in obj){
            let val = obj[item];
            temp[item] = typeof val == 'object'?rd.clone(val):val; //这里也没有判断是否为函数，因为对于函数，我们将它和一般值一样处理
        }
    }
    return temp;
}

// 对像合并
const extend = function(target, source){
	for(let i in source) {
		if(target[i] === undefined) { // 不冲突的，直接赋值 
			target[i] = source[i];
			continue;
		}
		// 冲突了，如果是Object，看看有么有不冲突的属性
		// 不是Object 则以（source）为准为主，
		if(source[i] instanceof Object) {
			if (source[i] instanceof Array) {
				for(let j in source[i]){
					extend(target[i][j], source[i][j])
				}
			} else {
				extend( target[i], source[i]);
			}
		} else {
			target[i] = source[i];
		}
	}
}






module.exports = {
  formatTime, clone, extend
}
